﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>GuiFromHwnd - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The GuiFromHwnd function retrieves the Gui object of a GUI window associated with the specified HWND." />
<meta name="ahk:equiv-v1" content="commands/Gui.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css">
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>GuiFromHwnd</h1>

<p>检索与指定的 HWND 关联的 Gui 窗口的 <a href="../objects/Gui.htm">Gui 对象</a>.</p>
<pre class="Syntax">GuiObj := <span class="func">GuiFromHwnd</span>(Hwnd <span class="optional">, RecurseParent := false</span>)</pre>

<h2 id="Parameters">参数</h2>
<dl>
  <dt>Hwnd</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>脚本先前创建的 GUI 窗口的窗口句柄(HWND), 或者如果 <em>RecurseParent</em> 为 true, 则脚本创建的 GUI 窗口的任何子窗口的窗口句柄.</p>
  </dd>
  <dt>RecurseParent</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#boolean">布尔值</a></p>
    <p>如果该参数为 true, 并且 <em>Hwnd</em> 标识了一个不是 GUI 的子窗口, 该函数将搜索并检索其最近的 GUI 的父窗口. 否则, 如果 <em>Hwnd</em> 没有直接识别 GUI 窗口, 该函数返回一个空字符串.</p>
  </dd>
</dl>
  
<h2 id="Return_Value">返回值</h2>
<p>类型: <a href="../objects/Gui.htm">Gui</a> 或<a href="../Concepts.htm#nothing">字符串(空)</a></p>
<p>函数返回与指定的 HWND 相关联的 <a href="../objects/Gui.htm">Gui 对象</a>, 如果没有该对象或 HWND 无效, 则返回一个空字符串.</p>

<h2 id="Remarks">备注</h2>
<p>例如, GUI 窗口的 HWND 可以传递给 <a href="OnMessage.htm">OnMessage</a> 函数, 也可以通过 <a href="../objects/Gui.htm#Hwnd">Gui.Hwnd</a>, <a href="WinExist.htm">WinExist</a> 或其他一些方法来检索.</p>

<h2 id="Related">相关</h2>
<p><a href="../objects/Gui.htm#Call">Gui()</a>, <a href="../objects/Gui.htm">Gui 对象</a>, <a href="../objects/GuiControl.htm">GuiControl 对象</a>, <a href="GuiCtrlFromHwnd.htm">GuiCtrlFromHwnd</a>, <a href="GuiControls.htm">Control 类型</a>, <a href="ListView.htm">ListView</a>, <a href="TreeView.htm">TreeView</a>, <a href="../objects/Menu.htm">Menu 对象</a>, <a href="Control.htm">Control 函数</a>, <a href="MsgBox.htm">MsgBox</a>, <a href="FileSelect.htm">FileSelect</a>, <a href="DirSelect.htm">DirSelect</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a class="ex_number" href="#ExBasic"></a> 通过使用刚刚创建的 GUI 窗口的 HWND 检索 Gui 对象, 并报告其标题.</p>
<pre>MyGui := Gui(, "Title of Window")
MyGui.Add("Text",, "Some text to display.")
MyGui.Show()

MsgBox(GuiFromHwnd(Gui.Hwnd).Title)</pre>
</div>

</body>
</html>